package com.alpha;

import org.apache.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.alpha.core.tools.ApplicationContextUtil;

@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {"com.alpha"})
@EnableTransactionManagement
public class Main  extends SpringBootServletInitializer {
	
	private static Logger logger = Logger.getLogger(Main.class);
	
//	private static final String MAPPER_SCAN_BASE_PACKAGE = "com.alpha.mybaits.mapper";
//	private static final String TYPE_ALIASES_PACKAGE = "com.alpha.mybaits.model";
	
//	//DataSource配置
//    @Bean
//    @ConfigurationProperties(prefix="spring.datasource")
//    public DataSource dataSource() {
//        return new org.apache.tomcat.jdbc.pool.DataSource();
//    }
//    
//    @Bean
//    @Autowired
//    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
//      final SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
//      sqlSessionFactoryBean.setDataSource(dataSource);
//      sqlSessionFactoryBean.setTypeAliasesPackage(TYPE_ALIASES_PACKAGE);
//      return sqlSessionFactoryBean.getObject();
//    }
//    
//    @Bean
//    public MapperScannerConfigurer mapperScannerConfigurer() throws Exception {
//    	final MapperScannerConfigurer msc = new MapperScannerConfigurer();
//    	msc.setBasePackage(MAPPER_SCAN_BASE_PACKAGE);
//    	msc.afterPropertiesSet();
//    	return msc;
//    }
//    
//    @Bean
//    public PlatformTransactionManager transactionManager() {
//        return new DataSourceTransactionManager(dataSource());
//    }
	
	public static void main(String[] args) {
		SpringApplication app = new SpringApplication(Main.class);  
	
		final ApplicationContext context = app.run(args);  
		ApplicationContextUtil.setApplicationContext(context);
        logger.info("============= SpringBoot Start Success =============");
	}
	
	@Override  
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {  
        return application.sources(Main.class);  
    }
	

	
	
}
